using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Meebey.SmartIrc4net;
using System.ComponentModel;

namespace dotIRC
{
    public class IrcChildForm : Form
    {
        public IrcSession irc;
        MainForm _parent;
        StatusForm _session;
        TreeNode _treeNode;

        public IrcChildForm() { } // For the form designer.

        public IrcChildForm(IrcSession session)
        {
            irc = session;
            Owner = session.Owner;
            _session = (StatusForm)Owner;

            MdiParent = Owner.MdiParent;
            _parent = (MainForm)MdiParent;

            Shown += new EventHandler(IrcChildForm_Shown);
            FormClosing += new FormClosingEventHandler(IrcChildForm_FormClosing);
        }

        void IrcChildForm_Shown(object sender, EventArgs e)
        {
            TreeNode parentNode = _session.TreeNode;
            _treeNode = parentNode.Nodes.Add(Text);
            _parent.treeViewForms.Add(_treeNode, this);
            if (parentNode.Nodes.Count == 1)
            {
                parentNode.Expand();
            }
        }

        void IrcChildForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            _session.TreeNode.Nodes.Remove(_treeNode);
            _parent.treeViewForms.Remove(_treeNode);
        }

        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public string NodeText
        {
            get
            {
                return _treeNode.Text;
            }
            set
            {
                _treeNode.Text = value;
            }
        }
        [Browsable(false),
        DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public IrcSession Session
        {
            get
            {
                return irc;
            }
        }
    }
}
